<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org" >

<head>
    <meta charset="UTF-8">
    <title>人气推荐</title>
</head>
<script type="text/javascript" th:src="@{/js/jquery-2.1.4.min.js}"></script>
<script type="text/javascript" th:src="@{/js/bootstrap-3.3.7-dist/js/bootstrap.min.js}"></script>
<link type="text/css" rel="stylesheet" th:href="@{/js/bootstrap-3.3.7-dist/css/bootstrap.min.css}">
<script type="text/javascript" th:src="@{/js/bootstrap-treeview/bootstrap-treeview.min.js}"></script>
<link type="text/css" rel="stylesheet" th:href="@{/js/bootstrap-treeview/bootstrap-treeview.min.css}">
<script type="text/javascript" th:src="@{/js/bootStrap-addTabs/bootstrap.addtabs.min.js}"></script>
<link type="text/css" rel="stylesheet" th:href="@{/js/bootStrap-addTabs/bootstrap.addtabs.css}">
<script type="text/javascript" th:src="@{/js/bootstrap-table/bootstrap-table.min.js}"></script>
<script type="text/javascript" th:src="@{/js/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}"></script>
<link type="text/css" rel="stylesheet" th:href="@{/js/bootstrap-table/bootstrap-table.min.css}">
<link type="text/css" rel="stylesheet" th:href="@{/js/bootstrap-fileinput/css/fileinput.css}">

<script type="text/javascript" th:src="@{/js/bootstrap-bootbox/bootbox.js}"></script>
<script type="text/javascript" th:src="@{/js/bootstrap-fileinput/js/fileinput.min.js}"></script>
<script th:src="@{/js/bootstrap-fileinput/js/locales/zh.js}"></script>

<body>

<div>
    <button type="button" class="btn btn-primary"
            data-toggle="modal" data-target="#myModal1">添加爆赞</button>

</div>

<!-- 修改模态框（Modal） -->
<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel1">修改商品</h4>
            </div>
            <div class="modal-body">

                <table id="myTable1"></table>
            </div>
            <!--  ====================================================   -->

            <div class="modal-footer">
                <button data-dismiss="modal" class="btn btn-default" type="button">关闭</button>
                <button class="btn btn-primary" type="button" onclick="sub()">确认修改</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>


<!-- 查询列表-->
<table id="myTable"></table>

</body>

<script >
    function sousuo(){
        $("#myTable").bootstrapTable("refresh", {
            "query": {
                product_name: $("#name").val(),
                maxprice: $("#maxprice").val(),
                minprice: $("#minprice").val(),


            }
        });
    }
    //爆赞商品表
    $("#myTable").bootstrapTable({
        url:"getListPop",
        columns:[
            {field:"xuan",checkbox:true},
            {field:"product_id",title:"编号"},
            {field:"product_name",title:"商品名称"},
            {field:"product_price",title:"商品价格"},
            {field:"product_category",title:"商品类型"},
            {field:"product_imgurl",title:"商品图片",formatter:function(value,row,index){
                    return "<img width='50px' height='50px' src='"+value+"'>";
                }},
            {field:"product_num",title:"商品数量"},
            {field:"product_description",title:"商品描述"},
            {field:"product_recommend",title:"人气推荐",formatter:function(value,row,index){
                if (value==1) {
                    return "爆赞推荐";
                }
                if (value==2) {
                    return "还需努力";
                }
                }},


        ],
        pagination:true,
        pageSize:10,
        pageList:[2,4,6,8,10],
        sidePagination: "client",
        toolbar:"#tb",
    })
        //非爆赞商品表
    $("#myTable1").bootstrapTable({
        url:"getListNonPop",
        columns:[
            {field:"xuan",checkbox:true},
            {field:"product_id",title:"编号"},
            {field:"product_name",title:"商品名称"},
            {field:"product_price",title:"商品价格"},
            {field:"product_category",title:"商品类型"},
            {field:"product_imgurl",title:"商品图片",formatter:function(value,row,index){
                    return "<img width='50px' height='50px' src='"+value+"'>";
                }},
            {field:"product_num",title:"商品数量"},
            {field:"product_description",title:"商品描述"},
            {field:"product_recommend",title:"人气推荐",formatter:function(value,row,index){
                    if (value==1) {
                        return "爆赞推荐";
                    }
                    if (value==2) {
                        return "还需努力";
                    }
                }},
            {field:"cxz",title:"操作",formatter:function(value,row){
                    var str='<button class="btn btn-info" onclick="del('+row.product_id+')">删除</button>';
                    var str2='<button class="btn btn-primary" onclick="getPopId('+row.product_id+')" data-toggle="modal" data-target="#myModal1">爆赞商品</button>';
                    return str+"   "+str2;
                }},
        ],
        pagination:true,
        pageSize:4,
        pageList:[2,4,6,8,10],
        sidePagination: "client",
        toolbar:"#tb1",
    })


    //爆赞商品
    function getPopId(product_id){
        $.ajax({
            url:"PopById",
            data:{id:product_id},
            success:function(){
                //bootbox.confirm("成功", "info")
                $("#myTable1").bootstrapTable('refresh');
                $("#myTable").bootstrapTable('refresh');
            }
        })
    }


    //修改回显
    function getProId(product_id){
        $.ajax({
            url:"getById",
            data:{id:product_id},
            type:"post",
            dataType:"json",
            success:function(data){
                $("#product_id").val(data.product_id);
                $("#product_name").val(data.product_name);
                $("#product_price").val(data.product_price);
                $("#product_category").val(data.product_category);
                $("#product_num").val(data.product_num);
                $("#product_description").val(data.product_description);
                $("#product_imgurl").val(data.product_imgurl);
                $("#file-Portrait").fileinput('refresh', {
                    initialPreview: "<img src="+data.product_imgurl+" height='180px' width='150px' class='file-preview-image'>",
                });
            }
        })
    }
    //修改
    function sub(){
        $.ajax({
            url:"updPro",
            type:"post",
            data:$("#myForm1").serialize(),
            success:function(){
                $('#myTable').bootstrapTable('refresh');//刷新表格
                $("#myModal1").modal('hide');

            },error:function(){
                $('#myTable').bootstrapTable('refresh');//刷新表格
                $("#myModal1").modal('hide');
            }
        })
    }
    //图片上传
    $('#file-Portrait').fileinput({
        language: 'zh', //设置语言
        uploadUrl: "upload", //上传的地址
        allowedFileExtensions : ['jpg', 'png','gif'],//接收的文件后缀,
        maxFileCount: 100,
        enctype: 'multipart/form-data',
        showUpload: true, //是否显示上传按钮
        showCaption: false,//是否显示标题
        browseClass: "btn btn-primary", //按钮样式
        previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
        msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",

        //dropZoneEnabled: false,//是否显示拖拽区域
        //minImageWidth: 50, //图片的最小宽度
        //minImageHeight: 50,//图片的最小高度
        //maxImageWidth: 1000,//图片的最大宽度
        //maxImageHeight: 1000,//图片的最大高度
        //maxFileSize: 0,//单位为kb，如果为0表示不限制文件大小
        //minFileCount: 0,
//     maxFileCount: 10, //表示允许同时上传的最大文件个数
//     enctype: 'multipart/form-data',
//     validateInitialCount:true,
//     previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
//     msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
    });
    //删除
    function del(product_id){
        $.ajax({
            url:"delPop",
            data:{id:product_id},
            success:function(){
                //bootbox.confirm("成功", "info")
                $("#myTable1").bootstrapTable('refresh');
                $("#myTable").bootstrapTable('refresh');
            }
        })
    }



</script>
</html>